package com.wangzy.game;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.RectF;
import android.util.AttributeSet;
import android.view.View;

import androidx.annotation.Nullable;

/**
 * @ProjectName: SportBS
 * @Date: 2023/1/19
 * @Desc:冷却进度条
 */
public class ResetProgressView extends View {

    private float progress;
    private Paint paint;

    public ResetProgressView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    Rect rect=null;
    RectF rectF=null;
    @Override
    protected void onDraw(Canvas canvas) {
        int width = canvas.getWidth();
        int height = canvas.getHeight();
        int rectWidth= (int) (Math.min(width,height)*0.7f);

        if(null==rect){

            int centerX=width/2;
            int centerY=height/2;

            rect=new Rect();
            rect.left=centerX-rectWidth/2;
            rect.top=centerY-rectWidth/2;
            rect.right=rect.left+rectWidth;
            rect.bottom=rect.top+rectWidth;
        }

        if(null==rectF){
            rectF=new RectF();
            rectF.set(rect.left,rect.top,rect.right,rect.bottom);
        }

        if(null==paint){
            paint=new Paint();
            paint.setAntiAlias(true);
        }

//        paint.setColor(Color.WHITE);
//        paint.setStrokeWidth(5);
//        paint.setStyle(Paint.Style.STROKE);
//        canvas.drawCircle(rect.centerX(),rect.centerY(),rectWidth/2,paint);

        paint.setStyle(Paint.Style.FILL);
        paint.setColor(Color.parseColor("#88000000"));

        float degree= progress*360;
        canvas.drawArc(rectF,0,degree,true,paint);

    }

    public float getProgress() {
        return progress;
    }

    public void setProgress(float progress) {
        this.progress = progress;
        postInvalidate();
    }
}